home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 136 / applic / column.c next >
C/C++ Source or Header  |  1987-05-12  |  2KB  |  86 lines

  1. /********************************************************************
  2. ;
  3. ;    file:        column.c
  4. ;    version:     V1.0 4/4/87 by Mike Sucher
  5. ;    description: Read in a text file line by line and produce
  6. ;                a 2-column output.
  7. ;
  8. ********************************************************************/
  9.  
  10. #include <stdio.h>
  11.  
  12. #define WIDTH 80
  13. #define LENGTH 66
  14. #define MARGIN 5
  15. #define GAP 3
  16.  
  17. main()
  18. {
  19.     FILE *input,*output;
  20.     int    brk,i,j,tot,toti,toto;
  21.     char line[WIDTH],buf[LENGTH][WIDTH];
  22.     char infile[50],outfile[50];
  23.  
  24.     printf("Column formatting program V1.0 4/87 by Mike Sucher\n\n");
  25.  
  26.     printf("Enter name of input file: ");gets(infile);putchar('\n');
  27.     if (!(input = fopen(infile,"r"))) {
  28.         printf("Error opening %s for input.  Exitting.\n",infile);
  29.         printf("Press Return: ");gets(line);
  30.         exit(1);
  31.     }    
  32.     printf("Enter name of output file: ");gets(outfile);putchar('\n');
  33.     putchar('\n');
  34.     if (!(output = fopen(outfile,"w"))) {
  35.         printf("Error opening %s for output.  Exitting.\n",outfile);
  36.         printf("Press Return: ");gets(line);
  37.         exit(1);
  38.     }
  39.     brk = 0;    
  40.     toti = toto = 0;
  41.     while(!brk) {
  42.         for(i=0;i<LENGTH;i++) {
  43.             for(j=0;j<WIDTH-1;j++) buf[i][j] = ' ';
  44.             buf[i][WIDTH-1]=0;
  45.         }
  46.         tot = 0;
  47.         for(i=GAP;i<LENGTH-GAP;i++) {
  48.             if(fgets(line,WIDTH,input)) {
  49.                 line[strlen(line)-1] = 0;
  50.                 line[WIDTH/2] = 0;
  51.                 strcpy(&buf[i][MARGIN],line);
  52.                 buf[i][MARGIN+strlen(line)] = ' ';
  53.             }
  54.             else {
  55.             brk++;break;
  56.             }
  57.         }
  58.         tot += i-GAP;
  59.         for(i=GAP;i<LENGTH-GAP;i++) {
  60.             if(fgets(line,WIDTH,input)) {
  61.                 line[strlen(line)-1] = 0;
  62.                 line[WIDTH/2] = 0;
  63.                 strcpy(&buf[i][MARGIN+(WIDTH/2)],line);
  64.             }
  65.             else {
  66.             brk++;break;
  67.             }
  68.         }
  69.         tot += i-GAP; toti += tot;
  70.  
  71.         tot = 0;
  72.         for(i=0;i<GAP;i++) fputc('\n',output);
  73.         for(i=GAP;i<LENGTH-GAP;i++) fprintf(output,"%s\n",buf[i]);
  74.         tot += i;
  75.         for(i=0;i<GAP;i++) fputc('\n',output);
  76.         tot += i; toto += tot;
  77.     }
  78.     fclose(input);
  79.     fclose(output);
  80.  
  81.     printf("%d lines read in from '%s'\n",toti,infile);
  82.     printf("%d lines output to '%s'\n",toto,outfile);
  83.     printf("Press Return to continue: ");gets(line);
  84.     exit(0);
  85. }
  86.